﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WeGet;

namespace WeAppsCenter.Core;
public class CheckForApplicationUpdates
{
    /// <summary>
    /// 获取需要更新的应用列表
    /// </summary>
    /// <returns>返回需要更新应用的 PackageName 数组</returns>
    public string[] GetUpdates()
    {
        var values = new List<string>();
        foreach (var packageName in Installation.GetInstalledApps())
        {
            GetAppInfo getAppInfo = new GetAppInfo();
            AppInfo latestAppInfo = getAppInfo.GetAppInfoByPackageName(packageName);
            AppInfo localAppInfo = getAppInfo.GetAppInfoByManifest($"{Settings.DefaultDirectory}\\{packageName}-{Channel.Publish}\\manifest.xml");
            if (latestAppInfo.Version!=localAppInfo.Version)
            {
                values.Add(packageName);
            }
        }
        return values.ToArray();
    }
}
